package servlet;

import bean.SupplierBean;
import util.JdbcUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@WebServlet(name = "SupplierServlet", value = "/SupplierServlet")
public class SupplierModifyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int sid =Integer.parseInt(request.getParameter("sid"));
        String sql ="SELECT * FROM supplier Where sid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,sid);
            ResultSet set = ps.executeQuery();
            set.absolute(1);
            SupplierBean su = new SupplierBean();
            su.setSid(set.getInt(1));
            su.setName(set.getString(2));
            su.setPerson(set.getString(3));
            su.setTel(set.getString(4));
            su.setEmail(set.getString(5));
            su.setAddress(set.getString(6));
            HttpSession session = request.getSession();
            session.setAttribute("su",su);
            request.getRequestDispatcher("suppliermodify.jsp").forward(request,response);
        }catch (Exception e) {
            e.printStackTrace();
        }


    }
}

